home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / Thread Manager Extension 2.0.1 / Sample Applications / Power Examples / SortPicts / Source / GWorldObj.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-03  |  5.1 KB  |  160 lines  |  [TEXT/MPS ]

  1. /*************************************************************************************
  2.  *
  3.  *    Create an Offscreen GWorld, Randomize and Sort it
  4.  *
  5.  *    GWorld.h    -    C Source
  6.  *
  7.  *      Copyright © Apple Computer, Inc. 1988 - 1993
  8.  *      All rights reserved.
  9.  *
  10.  *      Notice the inheritance of WindowObj
  11.  *
  12.  *************************************************************************************/
  13. #ifndef __GWORLDOBJ__
  14. #define __GWORLDOBJ__
  15.  
  16. #include "WindowObj.h"
  17. #include <QDOffscreen.h>
  18. #include "main.h"
  19. #include <Threads.h>
  20. #include <GestaltEqu.h>
  21. #include "WindowObj.Link"
  22.  
  23. #define        ABOUTDIALOG            128
  24. #define        ABOUTDIALOGPICT        3
  25. #define        ABOUTPICTURENAMEID    145
  26.  
  27. #define        PICTURESMENU        132
  28. #define        USEROPTIONSMENU        131
  29. #define        UO_ERASE            1
  30. #define        UO_QUALUDES            2
  31. #define        UO_CONTINUOUS5Sec    3
  32. #define        UO_CONTINUOUS0Sec    4
  33. #define        UO_SAVEWINDPOS        5
  34. #define        UO_SORT_0            6
  35. #define        UO_SORT_1            7
  36. #define        UO_BLANK            8
  37. #define        UO_SHOWTTYDELAY        9
  38. #define        UO_DECREASETTY        10
  39. #define        UO_INCREASETTY        11
  40.  
  41. #define        mSortAlgorithm        133
  42. #define        iShellSort            1
  43. #define        iHeapSort            2
  44. #define        iQuickSort            3
  45. #define        iRandomSort            5
  46.  
  47.  
  48. //    This is just lame... but MPW C++ doesn't support the inherited operator
  49. #define        inherited            WindowObj
  50.  
  51.  
  52. class    GWorldObj : public inherited {
  53. private:
  54.     int                    savedCount;
  55.     CGrafPtr            savedPort;
  56.     GDHandle            savedGDH;
  57.     PicHandle            sortPict;
  58.     Rect                worldPictRect;            //    Where in the GWorld the pict lies
  59.     Rect                windPictRect;            //    Where in the Window the Pict lies
  60.     GWorldPtr            sortGWorld;
  61.     long              **sortList;
  62.     long               *sortListPtr;
  63.     Size                sortListSize;            //    Usually called N in most text books
  64. #define        N            sortListSize            /* That sets it OK */
  65.     short                pictWidth,
  66.                         pictHeight,
  67.                         pictRowBytes;
  68.     long                threadResult;
  69.     Byte               *offscreenPtr;
  70.     Size                offset;
  71.     long                yieldTime;
  72.     GrafPtr                savePort;
  73.     short                percentComplete;        //    Used during randomization
  74.     
  75.     Boolean                randomizing;            //    True during the randomization process
  76.     Boolean                aboutBox;                //    True when this window is the about box!
  77.     Str255                windowTitle;            //    Held during drag!!
  78.     Boolean                needToUpdateWindowTitle;//    Set True when window Title Δ during drag
  79.     long                finishedTime;            //    Used for continuous operation
  80. public:
  81. //    User Options that apply to all windows
  82. static    short            gSortSize;                //    0 == Actual Picts, 1 == Cool, 2 == Totally art deco
  83. static    Boolean            gEraseWindow;            //    User defined... do we erase the window before CopyBits?
  84. static    short            gYieldDelay;            //    How long to wait before switching
  85. static    short            gNumPictures;            //    The number of pictures in resource fork
  86. static    MenuHandle        gPicturesMenu;            //    The place to hold the names of the picts
  87. static    short            gWindOffSet;            //    How far to set off each window...
  88. static    Boolean            gHasThreads;            //    Are threads present on this Mac??
  89. static    Boolean            gQualudesUpdate;        //    This Engages CopyBits to Copy to Whole window.. it's cool
  90. static    Boolean            gContinuous;            //    As soon as sorting is done, rescramble the whole mess!!
  91. static    short            gContinuousTime;        //    How long to wait.. 0Sec or 5Sec? 
  92. static    Boolean            gSaveWindowPositions;    //    When windows are moved... save their positions
  93. static    short            gNextBkgndWindowNum;    //    The next window to get Background events
  94. static    short            gSortAlgorithm;            //    Which menu item is selected
  95.  
  96.     short                sortAlgorithm;            //    Which sort for this window
  97.  
  98. #ifdef __powerc
  99.     ModalFilterUPP        AboutBoxFilterUPP;        //    A UniversalProcPtr
  100. #endif
  101.  
  102. private:
  103. //    The following is random number stuff
  104.     long                randomSeed;
  105.     Rect                copyBitsRect;
  106.  
  107. public:
  108.     Boolean                doneSorting;    //    Features based on during/post sort time
  109.     ThreadID            threadInfo;        // This was made public so it can be
  110.                                         //    set to Ø when the sort has completed.
  111.     Str255                pictureName;    //    Picture Name that the user selected
  112.     Boolean                yieldOnlyToMe;    //    True while the user holds down the mouse button
  113.  
  114.  
  115.     
  116. public:
  117. //    Window stuff
  118. virtual void    InitObj( void);
  119. virtual Boolean    NewWindowObj( void);
  120. virtual    Boolean    BeginNewThread( void);
  121. virtual    void    MouseClickObj( EventRecord *event);
  122. virtual void    BackGroundObj( void);                    //    Same as Idle obj, only background idle
  123. virtual void    IdleObj( void);
  124. virtual void    GrowWindowObj( EventRecord *event);
  125. virtual    Boolean    CloseWindowObj( void);
  126. virtual    void    DrawObj( void);
  127. virtual    void    DrawGrowIconObj( void);
  128. virtual    void    MenuObj( short menu, short item, EventRecord *event);
  129. virtual    void    AdjustMenusObj( void);
  130. virtual    Boolean    AboutObj( void);
  131. virtual    void    UpdateObj( void);
  132. virtual    void    DragWindowObj( EventRecord *event);
  133. virtual void    SetTitle( ConstStr255Param title);
  134.         Boolean    PrepareGWorld( void);
  135.         void    UseGWorld( void);
  136.         void    UnuseGWorld( void);
  137.  
  138. //    Sort kind-a stuff
  139.         void    ShellSort( void);
  140.         void    HeapSort( void);
  141.         void    BuildHeap( void);
  142.         void    Heapify( long size, long index);
  143.         void    QuickSort( void);
  144.         void    ChooseMedian( long a, long b, long c);
  145.         void    QuickSortEngine( long left, long right, char *);
  146.         void    ExchangeSortItem( long one, long theOther);
  147.         void    SetSortItem( long index, long data);
  148.         OSErr    YieldIfTime( char *mmuMode);
  149.  
  150. //    Scrmbling stuff
  151.         void    ScramblePict( void);
  152.  
  153. //    Random Number stuff
  154.         long    RandomPixel( long max);            // returns 0 ≤ random < max
  155. };
  156.  
  157.  
  158. #endif
  159.  
  160.